<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>3_回调ref调用次数问题</title>
</head>

<body>
    <div id="test"></div>
    <script type="text/javascript" src="../js/react.development.js"></script>
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <script type="text/babel">
        //1 创建类式组件
        class Weather extends React.Component {
            state = { isHot: true }
            showData = () => {
                const { input1 } = this
                alert(input1.value)
            }
            changeWeather = () => {
                const { isHot } = this.state
                this.setState({ isHot: !isHot })
            }
            saveInput = (currentNode) => {
                this.input1 = currentNode
            }
            render() {
                const { isHot } = this.state
                return (
                    <div>
                        {                          
                        /*
                            这种方式会执行两次
                            <input ref={(currentNode) => {
                            console.log(currentNode)
                            this.input1 = currentNode
                        }} type="text" placeholder='点击按钮提示数据' />
                        */
                        }
                        <input ref={this.saveInput} type="text" placeholder='点击按钮提示数据' />
                        <button onClick={this.showData}>点击 </button>
                        <div>今天的天气很{isHot ? '炎热' : "凉爽"}</div>
                        <button onClick={this.changeWeather}>切换天气 </button>
                    </div>
                )
            }

        }
        //2 渲染组件到页面 
        ReactDOM.render(<Weather />, document.getElementById('test'))
    </script>
</body>
</html>